using SM;
using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
namespace TVSGPP.search
{
	public class frmFindCustomerFree : Form
	{
		private Func objFunc = new Func();
		public string _ID = "";
		public string _Name = "";
		public string _Address = "";
		public string _Phone = "";
		public string _Age = "";
		public string _Gender = "";
		private bool Loading = false;
		private IContainer components = null;
		private Grid dgvCustomer;
		private Button btnClose;
		private Button btnSelect;
		public TextBox txtSearch;
		private Label label1;
		private DataGridViewTextBoxColumn ID;
		private DataGridViewTextBoxColumn NameCus;
		private DataGridViewTextBoxColumn Address;
		private DataGridViewTextBoxColumn Age;
		private DataGridViewTextBoxColumn Gender;
		private DataGridViewTextBoxColumn Phone;
		public frmFindCustomerFree()
		{
			this.InitializeComponent();
			this.txtSearch.Focus();
		}
		private void frmFindCustomerFree_Load(object sender, EventArgs e)
		{
			this.getProduct();
			this.Loading = true;
			this.txtSearch.Focus();
		}
		private void btnSelect_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void getProduct()
		{
			this.dgvCustomer.AutoGenerateColumns = false;
			SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
			string cmdText;
			if (this.txtSearch.Text.Trim() != "")
			{
				cmdText = "SELECT [ID], [Name], [Address], [Phone], [Age], Replace(Replace([Gender],'0',N'Nữ'),1,'Nam') AS  Gender FROM [TabCustomerFree] WHERE Rtrim(Ltrim(Name)) <> '' AND  Upper(Name) LIKE N'%" + this.txtSearch.Text.ToUpper() + "%' ORDER BY [Name]";
			}
			else
			{
				cmdText = "SELECT [ID], [Name], [Address], [Phone], [Age], Replace(Replace([Gender],'0',N'Nữ'),1,'Nam') AS  Gender FROM [TabCustomerFree] WHERE Rtrim(Ltrim(Name)) <> '' ORDER BY [Name]";
			}
			SqlCommand selectCommand = new SqlCommand(cmdText, sqlConnection);
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommand);
			DataSet dataSet = new DataSet();
			sqlConnection.Open();
			sqlDataAdapter.Fill(dataSet);
			this.dgvCustomer.DataSource = dataSet.Tables[0];
			sqlConnection.Close();
			sqlConnection.Dispose();
			sqlDataAdapter.Dispose();
			dataSet.Dispose();
		}
		private void dgvCustomer_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
		{
			this.btnSelect.PerformClick();
		}
		private void dgvCustomer_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			try
			{
				this._ID = this.dgvCustomer.Rows[e.RowIndex].Cells["ID"].Value.ToString();
				this._Name = this.dgvCustomer.Rows[e.RowIndex].Cells["NameCus"].Value.ToString();
				this._Address = this.dgvCustomer.Rows[e.RowIndex].Cells["Address"].Value.ToString();
				this._Phone = this.dgvCustomer.Rows[e.RowIndex].Cells["Phone"].Value.ToString();
				this._Age = this.dgvCustomer.Rows[e.RowIndex].Cells["Age"].Value.ToString();
				this._Gender = this.dgvCustomer.Rows[e.RowIndex].Cells["Gender"].Value.ToString();
			}
			catch
			{
			}
		}
		private void txtSearch_TextChanged(object sender, EventArgs e)
		{
			if (this.Loading)
			{
				this.getProduct();
			}
		}
		private void txtSearch_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Return)
			{
				if (this.txtSearch.Text != "")
				{
					this.dgvCustomer.Focus();
				}
			}
			else
			{
				if (e.KeyCode == Keys.Down)
				{
					this.dgvCustomer.Focus();
				}
			}
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			this._Name = "";
			this._Address = "";
			this._Phone = "";
			this._Age = "";
			this._Gender = "";
			base.Close();
		}
		private void frmFindCustomerFree_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
			else
			{
				if (e.KeyCode == Keys.F2)
				{
					this.btnSelect.PerformClick();
				}
			}
		}
		private void dgvCustomer_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Return)
			{
				this.btnSelect.PerformClick();
			}
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmFindCustomerFree));
			this.txtSearch = new TextBox();
			this.btnClose = new Button();
			this.btnSelect = new Button();
			this.label1 = new Label();
			this.dgvCustomer = new Grid();
			this.ID = new DataGridViewTextBoxColumn();
			this.NameCus = new DataGridViewTextBoxColumn();
			this.Address = new DataGridViewTextBoxColumn();
			this.Age = new DataGridViewTextBoxColumn();
			this.Gender = new DataGridViewTextBoxColumn();
			this.Phone = new DataGridViewTextBoxColumn();
			((ISupportInitialize)this.dgvCustomer).BeginInit();
			base.SuspendLayout();
			this.txtSearch.AcceptsReturn = true;
			this.txtSearch.Font = new Font("Arial", 10f);
			this.txtSearch.Location = new Point(104, 207);
			this.txtSearch.Name = "txtSearch";
			this.txtSearch.Size = new Size(162, 23);
			this.txtSearch.TabIndex = 9;
			this.txtSearch.TextChanged += new EventHandler(this.txtSearch_TextChanged);
			this.txtSearch.KeyDown += new KeyEventHandler(this.txtSearch_KeyDown);
			this.btnClose.BackColor = Color.FromArgb(224, 224, 224);
			this.btnClose.FlatAppearance.BorderColor = Color.FromArgb(128, 128, 255);
			this.btnClose.FlatStyle = FlatStyle.Flat;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new Point(347, 207);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(94, 23);
			this.btnClose.TabIndex = 11;
			this.btnClose.Text = "Thoát  [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = false;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.btnSelect.BackColor = Color.FromArgb(224, 224, 224);
			this.btnSelect.FlatAppearance.BorderColor = Color.FromArgb(128, 128, 255);
			this.btnSelect.FlatStyle = FlatStyle.Flat;
			this.btnSelect.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnSelect.Location = new Point(268, 207);
			this.btnSelect.Name = "btnSelect";
			this.btnSelect.Size = new Size(78, 23);
			this.btnSelect.TabIndex = 10;
			this.btnSelect.Text = "Chọn [ F2 ]";
			this.btnSelect.UseVisualStyleBackColor = false;
			this.btnSelect.Click += new EventHandler(this.btnSelect_Click);
			this.label1.BackColor = SystemColors.ButtonFace;
			this.label1.Location = new Point(1, 207);
			this.label1.Name = "label1";
			this.label1.Size = new Size(100, 23);
			this.label1.TabIndex = 12;
			this.label1.Text = "Tìm bệnh nhân : ";
			this.label1.TextAlign = ContentAlignment.MiddleCenter;
			this.dgvCustomer.AllowUserToAddRows = false;
			this.dgvCustomer.AllowUserToDeleteRows = false;
			this.dgvCustomer.AllowUserToResizeColumns = false;
			this.dgvCustomer.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvCustomer.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvCustomer.BackgroundColor = Color.White;
			this.dgvCustomer.BorderStyle = BorderStyle.Fixed3D;
			this.dgvCustomer.ColumnHeadersHeight = 22;
			this.dgvCustomer.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvCustomer.Columns.AddRange(new DataGridViewColumn[]
			{
				this.ID,
				this.NameCus,
				this.Address,
				this.Age,
				this.Gender,
				this.Phone
			});
			this.dgvCustomer.EnableHeadersVisualStyles = false;
			this.dgvCustomer.Location = new Point(1, 1);
			this.dgvCustomer.Name = "dgvCustomer";
			this.dgvCustomer.ReadOnly = true;
			this.dgvCustomer.RowHeadersVisible = false;
			this.dgvCustomer.RowHeadersWidth = 26;
			this.dgvCustomer.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			this.dgvCustomer.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvCustomer.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvCustomer.Size = new Size(440, 203);
			this.dgvCustomer.TabIndex = 0;
			this.dgvCustomer.CellDoubleClick += new DataGridViewCellEventHandler(this.dgvCustomer_CellDoubleClick);
			this.dgvCustomer.KeyDown += new KeyEventHandler(this.dgvCustomer_KeyDown);
			this.dgvCustomer.CellEnter += new DataGridViewCellEventHandler(this.dgvCustomer_CellEnter);
			this.ID.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.ID.DataPropertyName = "ID";
			this.ID.HeaderText = "ID";
			this.ID.Name = "ID";
			this.ID.ReadOnly = true;
			this.ID.Visible = false;
			this.NameCus.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.NameCus.DataPropertyName = "Name";
			this.NameCus.HeaderText = "Tên bệnh nhân";
			this.NameCus.MinimumWidth = 140;
			this.NameCus.Name = "NameCus";
			this.NameCus.ReadOnly = true;
			this.NameCus.Width = 140;
			this.Address.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Address.DataPropertyName = "Address";
			this.Address.HeaderText = "Địa chỉ";
			this.Address.MinimumWidth = 150;
			this.Address.Name = "Address";
			this.Address.ReadOnly = true;
			this.Age.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Age.DataPropertyName = "Age";
			dataGridViewCellStyle2.Alignment = DataGridViewContentAlignment.MiddleRight;
			this.Age.DefaultCellStyle = dataGridViewCellStyle2;
			this.Age.HeaderText = "Tuổi";
			this.Age.MinimumWidth = 45;
			this.Age.Name = "Age";
			this.Age.ReadOnly = true;
			this.Age.Width = 45;
			this.Gender.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Gender.DataPropertyName = "Gender";
			dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleCenter;
			this.Gender.DefaultCellStyle = dataGridViewCellStyle3;
			this.Gender.HeaderText = "Giới tính";
			this.Gender.MinimumWidth = 60;
			this.Gender.Name = "Gender";
			this.Gender.ReadOnly = true;
			this.Gender.Width = 60;
			this.Phone.DataPropertyName = "Phone";
			this.Phone.HeaderText = "Phone";
			this.Phone.Name = "Phone";
			this.Phone.ReadOnly = true;
			this.Phone.Visible = false;
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			this.BackColor = Color.White;
			base.ClientSize = new Size(443, 233);
			base.ControlBox = false;
			base.Controls.Add(this.label1);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.btnSelect);
			base.Controls.Add(this.txtSearch);
			base.Controls.Add(this.dgvCustomer);
			this.Cursor = Cursors.Hand;
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.FormBorderStyle = FormBorderStyle.FixedToolWindow;
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			this.MaximumSize = new Size(445, 235);
			this.MinimumSize = new Size(445, 235);
			base.Name = "frmFindCustomerFree";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.Manual;
			base.Load += new EventHandler(this.frmFindCustomerFree_Load);
			base.KeyDown += new KeyEventHandler(this.frmFindCustomerFree_KeyDown);
			((ISupportInitialize)this.dgvCustomer).EndInit();
			base.ResumeLayout(false);
			base.PerformLayout();
		}
	}
}
